package com.example;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class MServer {

    public static void main(String[] args) {
        try {
            new MServer();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    public MServer() throws Exception {
        ServerSocket server = new ServerSocket(8888);


        Map<User,Socket> userMap = new HashMap<>();

        List<User> userList = new ArrayList<>();
        for(int i=1;i<=5;i++){
            userList.add(new User("12"+i,"12"+i));
        }

        Socket socket = null;
        int ID = 0;
        while (true) {
            System.out.println("创建服务器，等待链接过来的客户端...");

            socket = server.accept();
            ID++;

            ServerThread st = new ServerThread(socket,userMap,ID,userList);
            new Thread(st).start();

            System.out.println(socket + "链接成功！");
        }

    }
}
